<template v-loading="loading">
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
      <el-form-item label="班级编号" prop="classCode">
        <el-input
          v-model="queryParams.classCode"
          placeholder="班级编号精确查询"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班级名" prop="className">
        <el-input
          v-model="queryParams.className"
          placeholder="班级名模糊查询"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="负责人" prop="leader">
          <el-input
          v-model="queryParams.leader"
          placeholder="负责人模糊查询"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="联系电话精确查询"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="classList" max-height="534">
      <el-table-column label="班级编号" prop="classCode" min-width="100" max-width="200"/>
      <el-table-column label="班级名称" prop="className" :show-overflow-tooltip="true" min-width="150" max-width="300" />
      <el-table-column label="负责人" prop="leader" :show-overflow-tooltip="true" min-width="150" max-width="300" />
      <el-table-column label="联系电话" prop="phone" min-width="100" max-width="200" />
      <el-table-column label="邮箱" prop="email" min-width="100" max-width="200" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleUpdate(scope.row)"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改角色配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" label-width="88px">
        <h4>课程信息</h4>
        <el-row>
          <el-col :span="6">
            <el-form-item label="班级编号:" prop="classCode">
              {{form.classCode}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="班级名称:" prop="className">
              {{form.className}}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="负责人:" prop="leader">
              {{form.leader}}
            </el-form-item>
          </el-col>
        </el-row>
        <h4 style="position:relate">
          该课程学生信息
        </h4>
        <el-table :data="form.list" height="438">
          <el-table-column label="学号" prop="userName" min-width="100" max-width="200"/>
          <el-table-column label="姓名" prop="nickName" min-width="100" max-width="200"/>
          <el-table-column label="考勤总次数" prop="count" min-width="80" max-width="200"/>
          <el-table-column label="签到次数" prop="ok" min-width="80" max-width="200"/>
          <el-table-column label="迟到次数" prop="late" min-width="80" max-width="200"/>
          <el-table-column label="早退次数" prop="leaveEarly" min-width="80" max-width="200"/>
          <el-table-column label="旷课次数" prop="truancy" min-width="80" max-width="200"/>
          <el-table-column label="出勤率" prop="percent" min-width="80" max-width="200"/>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listCourse,listCourseStudent,updateCourse,listDept } from "@/api/basic/course";
import { listClass,listClassStudent } from "@/api/basic/class";
// import { listRecord } from "@/api/basic/record";//用于查询考勤结果统计出勤率
import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数

export default {
  name: "Course",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 班级表格数据
      classList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //选中的学生的参数
      checkedStudent:{},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        classCode: undefined,
        className: undefined,
        leader: undefined,
        phone:undefined
      },
      // 表单参数
      form: {
        list:[],
      },
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    checkPermi,
    checkRole,
    /** 查询课程列表 */
    getList() {
      this.loading = true;
      listClass(this.queryParams).then( response => {
          this.classList = response.data.list;
          this.total = response.data.total;
          this.loading = false;
        })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        classCode: undefined,
        className:undefined,
        leader:undefined,
        percent:undefined,
        list:[],
      };
      this.teacherOptions = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.loading = true;
      [this.form.classCode,this.form.className,this.form.leader] = [row.classCode,row.className,row.leader];
      const classCode = row.classCode;
      this.teacherOptions.push({userName:this.form.tno,nickName:this.form.tname})
      listClassStudent({classCode:classCode}).then(response => {
        this.form.list = response.data.list;
        this.open = true;
        this.title = "班级详情";
        this.loading = false;
      });
    },
  }
};
</script>